package com.erp.module.crm

import android.content.Context
import android.util.Log
import com.erp.bean.Userdataonebean
import com.erp.Interface.OnUserDataInterface
import com.erp.pull.BasePullP
import com.erp.util.JsonUtil
import org.json.JSONArray
import org.json.JSONObject

/**
 * Created by Administrator on 2019/3/18/018.
 * 作者：刘洋
 */
class ICrmP(val context: Context, val V: CrmContract.CrmView, var mlist: MutableList<Userdataonebean>): BasePullP(),CrmContract.CrmP {
    val USERDATANAME = arrayOf("id", "customer_name", "ps_name", "shop_name", "customer_tel", "designer_name", "xiaoshouyuan_name", "crm_c_contract_num", "customer", "detailed_address", "country", "city", "province")
    val md : CrmModel= CrmModel()
    init {
        PullV=V
    }
    override fun getData(page: Int, pagesize: Int, onUserDataInterface: OnUserDataInterface) {
        md.setuserdatahttp(context,page,pagesize,USERDATANAME, FragmentCrm.souSuoBean,onUserDataInterface);
//        md.getcrmorderdata(context,page,pagesize, FragmentCrm.souSuoBean,onUserDataInterface);
    }

    override fun jsondata(data: String?) {
        Log.d("jsondata=====",data);
        if (data==null){
            return
        }
        try {
            val ja = JSONArray(data)
            for (i in 0 until ja.length()) {
                val jo = ja.get(i) as JSONObject
                val userdataonebean = Userdataonebean()
                userdataonebean.shop_name = JsonUtil.getvolue(jo,"shop_name")
                userdataonebean.crm_oid = JsonUtil.getvolue(jo,"id")
//                userdataonebean.crm_oid = JsonUtil.getvolue(jo,"crm_oid")
                var province = JsonUtil.getvolue(jo,"province")
                if (province == "-1") {
                    province = ""
                }
                userdataonebean.dizhi = province + JsonUtil.getvolue(jo,"city") + JsonUtil.getvolue(jo,"country")+ JsonUtil.getvolue(jo,"detailed_address")
                userdataonebean.customer_name = JsonUtil.getvolue(jo,"customer_name")
                userdataonebean.customer_tel = JsonUtil.getvolue(jo,"customer_tel")
                userdataonebean.ps_name = JsonUtil.getvolue(jo,"ps_name")
                userdataonebean.crm_c_contract_num = JsonUtil.getvolue(jo,"crm_c_contract_num")
                userdataonebean.xiaoshouyuan_name = JsonUtil.getvolue(jo,"xiaoshouyuan_name")
                userdataonebean.designer_name = JsonUtil.getvolue(jo,"designer_name")


                userdataonebean.oid = JsonUtil.getvolue(jo,"oid")
                userdataonebean.onum = JsonUtil.getvolue(jo,"onum")
                userdataonebean.contract_num = JsonUtil.getvolue(jo,"o_contract_num")
                userdataonebean.customer = JsonUtil.getvolue(jo,"customer")
                userdataonebean.tel = JsonUtil.getvolue(jo,"tel")
                userdataonebean.ot_name = JsonUtil.getvolue(jo,"ot_name")
                userdataonebean.content_description = JsonUtil.getvolue(jo,"content_description")
                userdataonebean.special_status = JsonUtil.getvolue(jo,"special_status")
                userdataonebean.special_service_cat = JsonUtil.getvolue(jo,"special_service_cat")
                userdataonebean.o_special_service_cat = JsonUtil.getvolue(jo,"o_special_service_cat")



                mlist.add(userdataonebean)
                Log.d("jsondata",mlist.toString())
            }
        } catch (e: Exception) {
            e.printStackTrace()
            Log.d("jsondata",e.toString())
        }
    }

    override fun listClean() {
        mlist.clear()
    }
}